package com.lin.bootstudy.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.context.annotation.Configuration;

@Configuration
@Aspect
public class TotalRuntime {

    @Pointcut("execution(* com.lin.bootstudy.service.impl.*.*(..))")
    public void pointcut(){}

//    @Around("pointcut()")
    public Object TotalRuntime(ProceedingJoinPoint jpt) throws Throwable{
        Signature signature = jpt.getSignature();
        String className = signature.getDeclaringTypeName();
        String methodName = signature.getName();

        long start=System.currentTimeMillis();
        for (int i = 0; i < 100000; i++){
            jpt.proceed();
        }
        long end=System.currentTimeMillis();
        System.out.println("万次"+className+"."+methodName+"的运行时间："+(end-start)+"ms");
        return jpt.proceed();
    }


}
